﻿using Microsoft.Data.SqlClient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RescueApp.Data;
using RescueApp.Model;
using EFCoreRepository.Extensions;


namespace RescueAPP.UI.Common
{
    public static class DbHelper
    {
        //public static bool IsExistsWithSql(RescueContext db, int Id)
        //{
        //    string sql = @"select * from [dbo].[RescueItem] where Id=@Id";
        //    IDictionary<string, object> dict = new Dictionary<string, object>();
        //    dict.Add("@Id", Id);
        //    SqlParameter[] parameters = dict.ToSqlParameters();
        //    var rescueitems = db.SqlQuery<RescueApply>(sql, parameters);
        //    if (rescueitems.Any())
        //    {
        //        return true;
        //    }
        //    return false;

        //}

        public static bool IsExistsWithORM(RescueContext db, int Id)
        {
            var rescueitems = db.RescueApplies.Where(x => x.RescueID == Id);
            if (rescueitems.Any())
            {
                return true;
            }
            return false;
        }

        public static bool IsExistsWithORM2(RescueContext db, int Id)
        {
            var rescueitems = db.RescueDispatches.Where(x => x.DispatchID == Id);
            if (rescueitems.Any())
            {
                return true;
            }
            return false;
        }
    }
}
